package top.dark.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Author: Darkn
 * description:
 * Create Time: 2021/5/4 21:46
 */
@Service
public class SpringMQ_Consumer {
//    @Resource(name = "jmsTemplateTopic")
    @Resource(name = "jmsTemplateQueue")
    private JmsTemplate jmsTemplate;
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-activemq.xml");
        SpringMQ_Consumer springMQ_consumer = applicationContext.getBean(SpringMQ_Consumer.class);
        for (; ; ) {
            String returnValue = (String) springMQ_consumer.jmsTemplate.receiveAndConvert();
            if ("exit-".equals(returnValue)) {
                System.exit(-1);
            }
            System.out.println("****消费者收到的消息:   " + returnValue);
        }
    }
}
